<template>
	<view style="padding-bottom: 20rpx;">
		<u-navbar title="第一步" :border-bottom='false' back-icon-size='48'></u-navbar>
		<u-gap height="20" bg-color="#F2F2F7"></u-gap>
		<view class="shopInfo">
			<view class="title">
				店铺信息
			</view>
			<view class="shopInfo-li">
				<view class="text">店铺名称</view>
				<input type="text" v-model="shopName" placeholder="请输入店铺名称" />
			</view>
			<view class="shopInfo-li">
				<view class="text">店铺说明</view>
				<input type="text" v-model='shopCont' placeholder="请输入店铺说明" />
				<u-icon style='margin-left: auto;' name="arrow-right" color="#999999" size="28"></u-icon>
			</view>
			<!-- 			<view class="title" style="font-size: 28rpx;font-weight: 400;">
				配置营业日期
			</view>
			<view class="daytime">
				<view class="dayItem">
					周一至周五
				</view>
				<view class="dayItem">
					周一至周五
				</view>
				<view class="dayItem">
					周一至周五
				</view>
				<view class="dayItem">
					周一至周五
				</view>
			</view>
			<view class="shopInfo-li">
				<view class="text">营业开始时间</view>
				<input type="text" placeholder="请选择时间" />
				<u-icon style='margin-left: auto;' name="arrow-right" color="#999999" size="28"></u-icon>
			</view>
			<view class="shopInfo-li">
				<view class="text">营业结束时间</view>
				<input type="text" placeholder="请选择时间" />
				<u-icon style='margin-left: auto;' name="arrow-right" color="#999999" size="28"></u-icon>
			</view> -->
		</view>
		<u-gap height="20" bg-color="#F2F2F7"></u-gap>
		<view class="shopInfo">
			<view class="shopInfo-li">
				<view class="text">选择经营类目</view>
				<input type="text" placeholder="请选择" disabled v-model="shopType" />
				<u-icon style='margin-left: auto;' name="arrow-right" color="#999999" size="28"
					@click="showPciker=true"></u-icon>
			</view>
			<view class="shopInfo-li">
				<view class="text">人均消费</view>
				<input type="number" v-model="peoPrice" placeholder="请输入人均消费" />
			</view>
			<view class="shopInfo-li">
				<view class="text">所在地区</view>
				<input type="text" placeholder="请选择" v-model='detAddr' disabled />
				<u-icon style='margin-left: auto;' name="arrow-right" color="#999999" size="28" @click="showCity=true">
				</u-icon>
			</view>
			<view class="shopInfo-li">
				<view class="text">详细地址</view>
				<input type="text" v-model="address" placeholder="请输入店铺地址" />
			</view>
			<view class="title" style="font-size: 28rpx;font-weight: 400;">
				设施与福利
			</view>
			<view class="checkBox">
				<u-checkbox-group @change="changeFn">
					<u-checkbox v-model="item.checked" v-for="(item, index) in list" :key="index" :name="item.id">
						{{item.name}}
					</u-checkbox>
				</u-checkbox-group>
			</view>
		</view>
		<u-gap height="20" bg-color="#F2F2F7"></u-gap>
		<view class="imgBox">
			<view class="title">
				上传照片
			</view>
			<view class="coverBox">
				<view class="tip">
					店铺封面 <text>(推荐尺寸 340x258）</text>
				</view>
				<view class="addPic" v-if="shopIcon">
					<image style="width: 100%;height: 100%;" :src="'https://api.loveworldzh.com/'+shopIcon" mode="">
					</image>
				</view>
				<view class="addPic" @click="uploadShopIcon" v-else>
					<image src="../../../../static/imgs/xiangji.png" mode=""></image>
				</view>
			</view>
			<view class="envBox">
				<view class="tip">
					环境照片 <text>(推荐尺寸 336x226）</text>
				</view>
				<view class="imgs">
					<view class="img-li" v-for="(img,index) in imgList" :key='index'>
						<image class="icon" :src="'https://api.loveworldzh.com/'+img" mode=""></image>
						<u-icon class='close' name="close-circle-fill" color="rgba(0, 0, 0, 0.32)" size="40"
							@click="del(index)"></u-icon>
					</view>
					<view class="addPic" @click="uploadShopIconMore">
						<image src="../../../../static/imgs/xiangji.png" mode=""></image>
					</view>
				</view>
			</view>
		</view>
		<view class="next" @click="next">
			下一步
		</view>
		<u-select v-model="showPciker" :list="selectList" @confirm='confirmFn'></u-select>
		<u-picker v-model="showCity" mode="region" @confirm='cityConfirm'></u-picker>

	</view>
</template>

<script>
	import myRequest from '@/api/index.js'
	export default {
		data() {
			return {
				showCity: false,
				showPciker: false,
				shopName: '', //店铺名
				shopCont: '', // 店铺说明
				shopType: '',
				shopTypeId: '', // 店铺类别
				peoPrice: '', //人均消费
				province: '', //省
				city: '', // 市
				district: '', // 显
				detAddr: '',
				address: '', // 地址
				tags: '', //福利
				shopIcon: '', //门店封面
				list: [{
						name: 'WiFi',
						checked: false,
						id: 1
					},
					{
						name: '充电宝',
						checked: false,
						id: 2
					},
					{
						name: '停车场',
						checked: false,
						id: 3
					},
					{
						name: '茶水',
						checked: false,
						id: 4
					},
					{
						name: '饮料',
						checked: false,
						id: 5
					}
				],
				selectList: [],
				imgList: [],
				images: '' // 多图
			}
		},
		onLoad() {
			this.getType()
		},
		methods: {
			del(index) {
				this.imgList.splice(index, 1)
				this.images = this.imgList.toString()
			},
			uploadShopIconMore() {
				let that = this
				uni.chooseImage({
					count: 8,
					sizeType: ['original'],
					sourceType: ['album'], //从相册选择
					success: function(res) {
						that.showPop = false
						that.uploadImgs(res.tempFilePaths)
					}
				});
			},

			// 多图
			uploadImgs(imgFiles) {
				let that = this
				imgFiles.forEach(itemFiles => {
					uni.uploadFile({
						url: that.$baseURL + 'upload/up',
						filePath: itemFiles,
						name: 'file',
						success: (uploadFileRes) => {
							let obj = JSON.parse(uploadFileRes.data)
							if (obj.status) {
								if (that.imgList.length > 7) {
									uni.showToast({
										title: '最多上传9张图片',
										icon: 'none'
									})
									return
								} else {
									that.imgList.push(obj.path)
									that.images = that.imgList.toString()
								}
							}
						}
					});
				})
			},

			// 单图上传
			uploadImg(imgFiles) {
				let that = this
				uni.uploadFile({
					url: that.$baseURL + 'upload/up',
					filePath: imgFiles[0],
					name: 'file',
					success: (uploadFileRes) => {
						let obj = JSON.parse(uploadFileRes.data)
						if (obj.status) {
							that.shopIcon = obj.path
						}
					}
				});
			},
			// 封面上传
			uploadShopIcon() {
				let that = this
				uni.chooseImage({
					count: 1,
					sizeType: ['original'],
					sourceType: ['album'],
					success: function(res) {
						console.log(res)
						let imgFiles = res.tempFilePaths
						that.uploadImg(imgFiles)
					}
				})
			},
			// 福利选择
			changeFn(e) {
				this.tags = e.toString()
				console.log(this.tags)
			},
			cityConfirm(e) {
				this.detAddr = e.province.label + ' ' + e.city.label + ' ' + e.area.label
				this.province = e.province.value + '0000'
				this.city = e.city.value + '00'
				this.district = e.area.value
			},

			confirmFn(e) {
				this.shopType = e[0].label
				this.shopTypeId = e[0].value
			},
			// 店铺类目
			async getType() {
				let res = await myRequest.getCategorytype()
				if (res.status) {
					res.data.forEach(item => {
						let obj = {
							value: '',
							label: ''
						}
						obj.value = item.id
						obj.label = item.cate_name
						this.selectList.push(obj)
					})
				}
			},

			next() {
				let {
					shopName,
					shopCont,
					shopTypeId,
					peoPrice,
					province,
					city,
					district,
					address,
					tags,
					shopIcon,
					images
				} = this
				if (!shopName || !shopCont || !shopTypeId || !peoPrice || !province || !province || !city || !district || !
					address || !tags || !shopIcon || !images) {
					uni.showToast({
						title: '请输入完整信息',
						icon: 'none'
					})
					return
				}
				
				let obj = {
					shopName,
					shopCont,
					shopTypeId,
					peoPrice,
					province,
					city,
					district,
					address,
					tags,
					shopIcon,
					images
				}
				this.$store.commit('changeShopStep',obj)
				uni.navigateTo({
					url: './stepTwo'
				})
			}
		}
	}
</script>

<style>
	page {
		background-color: #FFFFFF;
	}
</style>
<style lang="scss" scoped>
	.shopInfo {
		width: 100%;
		height: auto;
		background-color: #FFFFFF;
		padding: 0 20rpx;

		.title {
			width: 100%;
			height: 88rpx;
			font-size: 32rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #333333;
			line-height: 88rpx;
		}

		.shopInfo-li {
			width: 100%;
			height: 88rpx;
			display: flex;
			align-items: center;

			input {
				height: 88rpx;
				font-size: 28rpx;
				font-family: PingFang SC;
				font-weight: 400;
				color: #333333;
			}

			.text {
				width: 30%;
				font-size: 28rpx;
				font-family: PingFang SC;
				font-weight: 400;
				color: #333333;
			}
		}

		.daytime {
			width: 100%;
			height: 88rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;

			.dayItem {
				width: 168rpx;
				height: 56rpx;
				background: #F2F2F7;
				border-radius: 8rpx;
				font-size: 24rpx;
				font-family: PingFang SC;
				font-weight: 400;
				color: #666666;
				text-align: center;
				line-height: 56rpx;
			}
		}

		.checkBox {
			width: 100%;
			height: 88rpx;
			display: flex;
			align-items: center;
		}

	}

	.imgBox {
		padding: 0 20rpx;
		width: 100%;
		height: auto;
		background-color: #FFFFFF;

		.title {
			width: 100%;
			height: 88rpx;
			line-height: 88rpx;
			font-size: 32rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #333333;
		}

		.coverBox {
			.tip {
				font-size: 28rpx;
				font-family: PingFang SC;
				font-weight: 400;
				color: #333333;

				text {
					margin-left: 4rpx;
					font-size: 24rpx;
					font-family: PingFang SC;
					font-weight: 400;
					color: #666666;
				}
			}

			.addPic {
				margin-top: 16rpx;
				width: 168rpx;
				height: 168rpx;
				background: #F2F2F7;
				border-radius: 8rpx;
				display: flex;
				align-items: center;
				justify-content: center;

				image {
					width: 68rpx;
					height: 68rpx;
				}
			}
		}

		.envBox {
			margin-top: 32rpx;

			.tip {
				font-size: 28rpx;
				font-family: PingFang SC;
				font-weight: 400;
				color: #333333;

				text {
					margin-left: 4rpx;
					font-size: 24rpx;
					font-family: PingFang SC;
					font-weight: 400;
					color: #666666;
				}
			}

			.imgs {
				display: flex;
				align-items: center;
				flex-wrap: wrap;
				margin-top: 16rpx;

				.img-li {
					position: relative;
					width: 168rpx;
					height: 168rpx;
					margin-right: 10rpx;
					margin-bottom: 10rpx;

					&:nth-child(4n) {
						margin-right: 0rpx;
					}

					.close {
						position: absolute;
						top: 6rpx;
						right: 6rpx;
						z-index: 99;
					}

					.icon {
						position: absolute;
						width: 168rpx;
						height: 168rpx;
					}
				}

				.addPic {
					width: 168rpx;
					height: 168rpx;
					background: #F2F2F7;
					border-radius: 8rpx;
					display: flex;
					align-items: center;
					justify-content: center;

					image {
						width: 68rpx;
						height: 68rpx;
					}
				}
			}
		}
	}

	.next {
		width: 670rpx;
		height: 100rpx;
		background: linear-gradient(180deg, #3FA3F9 0%, #2D7BF7 100%);
		border-radius: 16rpx;
		margin: 70rpx auto 0;
		line-height: 100rpx;
		text-align: center;
		font-size: 36rpx;
		font-family: PingFangSC-Medium;
		color: #FFFFFF;
	}
</style>
